package jmine.tec.aom.builder;

import jmine.tec.aom.domain.Property;
import jmine.tec.aom.domain.PropertyGroup;
import jmine.tec.aom.domain.PropertyType;
import bancosys.tec.persist.builders.AbstractDBBuilder;

/**
 * @author jrenaut
 */
public class PropertyBuilder extends AbstractDBBuilder<Property> {

    public static PropertyBuilder aProperty() {
        return new PropertyBuilder();
    }

    private String mnemonic = "a property mnemonic";

    private String name = "a property name";

    private String description = "a property description";

    private PropertyType propertyType = null;

    private PropertyGroup propertyGroup = null;

    /**
     * {@inheritDoc}
     */
    @Override
    protected Property doBuild() {
        Property p = this.createBean();
        p.setMnemonic(this.mnemonic);
        p.setName(this.name);
        p.setDescription(this.description);
        p.setPropertyType(this.getPropertyType());
        p.setPropertyGroup(this.getPropertyGroup());
        return p;
    }

    public PropertyBuilder withMnemonic(String mnemonic) {
        this.mnemonic = mnemonic;
        this.name = mnemonic;
        return this;
    }

    public PropertyBuilder withName(String name) {
        this.name = name;
        return this;
    }

    public PropertyBuilder withDescription(String description) {
        this.description = description;
        return this;
    }

    public PropertyBuilder withPropertyType(PropertyType propertyType) {
        this.propertyType = propertyType;
        return this;
    }

    public PropertyBuilder withPropertyGroup(PropertyGroup propertyGroup) {
        this.propertyGroup = propertyGroup;
        return this;
    }

    private PropertyType getPropertyType() {
        if (this.propertyType == null) {
            this.propertyType = PropertyTypeBuilder.aPropertyType().save();
        }
        return this.propertyType;
    }

    private PropertyGroup getPropertyGroup() {
        if (this.propertyGroup == null) {
            this.propertyGroup = PropertyGroupBuilder.aPropertyGroup().save();
        }
        return this.propertyGroup;
    }

}
